<?php
$appid = $_POST['appId'];
$appsecret = $_POST['appSecret'];
$code = $_POST['code'];
function wx_curl($url, $type = 'get', $res = 'json', $arr = '') {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if ($type == 'post') {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
    }
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $appsecret . "&code=" . $code . "&grant_type=authorization_code ";
$arr = json_decode(wx_curl($url), true);
$access_token = $arr['access_token'];
$openid = $arr['openid'];
//拉取用户的详细信息
$url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $openid . "&lang=zh_CN";
$res = wx_curl($url);
echo $res;
